<?php

namespace Boosen\Company;

use Illuminate\Routing\Router;
use Illuminate\Support\ServiceProvider;
use Route;

class CompanyServiceProvider extends ServiceProvider
{
	protected $commands = [
        \Boosen\Company\app\Console\Commands\InfoSpider::class,
        \Boosen\Company\app\Console\Commands\CNBaseUrlSpider::class,
        \Boosen\Company\app\Console\Commands\CNCompanyUrlSpider::class,
        \Boosen\Company\app\Console\Commands\CNCompanyInfoSpider::class,
        \Boosen\Company\app\Console\Commands\CNBaseProductUrlSpider::class,
        \Boosen\Company\app\Console\Commands\CNProductUrlSpider::class,
        \Boosen\Company\app\Console\Commands\ProxySpider::class
    ];
	public $routeFilePath = '/routes/boosen/company.php';


	public function boot()
	{
		// $this->loadViewsFrom(resource_path('views/vendor/boosen/company'), 'company');
        // - then the stock views that come with the package, in case a published view might be missing
        $this->loadViewsFrom(realpath(__DIR__.'/resources/views'), 'company');

        $this->setupRoutes($this->app->router);
        $this->loadHelpers();
        // if ($this->app->runningInConsole()) {
            $this->commands($this->commands);
        // }
	}

	public function register()
	{
		$this->mergeConfigFrom(
            __DIR__.'/config/boosen/company.php', 'boosen.company'
        );
	}

    /**
     * Load the Backpack helper methods, for convenience.
     */
    public function loadHelpers()
    {
        require_once __DIR__.'/helpers.php';
    }

    public function setupRoutes(Router $router)
    {
        // by default, use the routes file provided in vendor
        $routeFilePathInUse = __DIR__.$this->routeFilePath;

        // but if there's a file with the same name in routes/backpack, use that one
        if (file_exists(base_path().$this->routeFilePath)) {
            $routeFilePathInUse = base_path().$this->routeFilePath;
        }

        $this->loadRoutesFrom($routeFilePathInUse);
    }

	public function publishFiles()
    {

    }
}